package fr.playsoft.psas;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Toast;

public class CommandPopup extends Activity {
    
	private boolean bInPOpupMode = false;
	private View frame2;
	private View popup;
	
	/** Called when the activity is first created. */
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
				
		setContentView(R.layout.comamndpopup);
		
		frame2 = findViewById(R.id.frame2);
		popup = findViewById(R.id.frame2_popup);
		frame2.setVisibility(View.INVISIBLE);
		
	}
	
	public void onOpenPickerClick(View v) {
		openPopup();
	}
	
	public void onOpenPickerClick2(View v) {
		openPopup();
	}
	
	public void onEmptySpaceClick(View v) {
		closePopup();
	}
	
	public void onPopupEmptySpaceClick(View v) {
		
	}
	
	private void openPopup() {
		bInPOpupMode = true;
		
		frame2.setVisibility(View.VISIBLE);
		Animation zoominAnim = AnimationUtils.loadAnimation(this, R.anim.anim_zoomin);
		popup.startAnimation(zoominAnim);
	}
	
	private void closePopup() {
		bInPOpupMode = false;
		Animation zoomoutAnim = AnimationUtils.loadAnimation(this, R.anim.anim_zoomout);
		popup.startAnimation(zoomoutAnim);
		
		zoomoutAnim.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) { }
			
			public void onAnimationRepeat(Animation animation) { }
			
			public void onAnimationEnd(Animation animation) {
				frame2.setVisibility(View.INVISIBLE);
			}
		});
		
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{
		if(keyCode==KeyEvent.KEYCODE_BACK && bInPOpupMode) {
			closePopup();
			return true;
		}
		return super.onKeyDown(keyCode, event);
    }
	
	public void onPopupButtonClick(View v) {
		if(bInPOpupMode) {
			closePopup();
			Toast.makeText(this, "Popup Button Click", Toast.LENGTH_SHORT).show();
		}
	}
	
}